<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class collegian  extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
    
                public function __construct() {
                    parent::__construct();
                    $this->authen_model->CheckPermission();
                    $this->load->model("collegian_model");
                }
	public function index()
	{
                      $this->add_collegian_form();
	}
                
                /* เรียกดูข้อมูลนักศึกษาจากรหัสสาขาที่ระบุ */
                public function get_collegian_form_major_id( $major_id ){
                     $this->db->select("*")->from("collegian")->where("ref_major_id","$major_id");
                     return $this->db->get();
                }

                public function add_collegian_form(){
                        $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->setContent($this->load->view("collegian/frm_student_add",$data,true))
                                ->setTitle("เพิ่มข้อมูลนักศึกษา")
                                ->rander();
                }
                
                public function update_collegian_form(){
                        if(isset($_POST["coll_id"])){
                            print_r($_POST);
                              $this->collegian_model->update_collegian($_POST);
                        }
                }
                
                public function view_collegian(){
                        $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->setContent($this->load->view("collegian/view_collegians",$data,true))
                                ->setTitle("แสดงข้อมูลนักศึกษา")
                                ->rander();
                }
                
                public function get_dialog_edit_collegians(){
                    if(isset($_POST["coll_id"])){
                        $data["collegian_datay"] = $this->collegian_model->get_collegian_by_id( $_POST["coll_id"] );
                        $data["majors"] = $this->collegian_model->get_majors();
                        $this->load->view("collegian/dialog_edit_collegians",$data);
                    }
                }
                
                public function search_collegian(){
                   
                    $data["collegian_datay"] = $this->collegian_model->search_collegian(
                            mysql_escape_string($_POST["txt_search"]) ,
                            mysql_escape_string($_POST["group_type"])
                    );
                    $data["count"] = $this->db_model->getCount();
                    $this->load->view("collegian/view_collegian_table",$data);
                }

                public function  add_user(){
                    error_reporting(0);
                    $sql = "INSERT INTO collegian   
                               VALUES(
                                        NULL , '$_POST[txt_name]' , '$_POST[txt_code]' , '$_POST[gender]' ,
                                        '$_POST[year]-$_POST[month]-$_POST[day]' , '$_POST[group_type]',
                                        '$_POST[phone_number]' , '$_POST[email]' 
                               )";
                        $this->db->query($sql);
                        if($this->db->affected_rows() > 0){
                            print(
                                    '<query>
                                        <status  q="true"></status>
                                    </query>'
                                    );
                        }else{
                            print(
                                    '<query>
                                        <status  q="false"></status>
                                    </query>'
                                    );
                        }
                }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */